import Vue from 'vue'
Vue.directive('scroll', {
  inserted (el, binding, vnode) {
    window.onscroll = () => {
      if (document.documentElement.scrollTop > binding.value) {
        el.style.backgroundColor = 'SaddleBrown'
        el.style.color = 'black'
      } else {
        el.style.backgroundColor = 'transparent'
        el.style.color = '#fff'
      }
    }
  },
  unbind () {
    window.onscroll = null
  }
})

Vue.directive('focus', {
  inserted: function (el) {
    // 聚焦元素
    el.focus()
  }
})
